package com.kamistoat.meimeimall.meimeimallcart.web;

import com.kamistoat.meimeimall.common.annotation.DubboAndHTTPExceptionCatch;
import com.kamistoat.meimeimall.common.annotation.LoginRequired;
import com.kamistoat.meimeimall.common.constant.DatabaseConstant;
import com.kamistoat.meimeimall.common.utils.R;
import com.kamistoat.meimeimall.meimeimallcart.dao.CartDao;
import com.kamistoat.meimeimall.meimeimallcart.entity.CartEntity;
import com.kamistoat.meimeimall.meimeimallcart.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(tags = "商品详情页操作")
@RestController
@RequestMapping("web")
public class ProductPageController {
    protected Logger logger = LoggerFactory.getLogger(ProductPageController.class);

    @Autowired
    CartService cartService;

    /**
     * 在商品详情页。将一件商品添加到购物车
     */
    @ApiOperation("在商品详情页，将一件商品添加到缓存购物车")
    @LoginRequired
    @PostMapping("/add_to_cart")
    @DubboAndHTTPExceptionCatch
    public R addToCart(@RequestParam Long skuId, @RequestParam Integer num) {
        cartService.addToCart(skuId, num);
        return R.ok();
    }

    @Autowired
    CartDao cartDao;

    @GetMapping("/insert")
    public R insert() {
        CartEntity cartEntity = new CartEntity();
        cartEntity.setMemberId(1L);
        cartEntity.setRemark("hhhh");
        cartEntity.setDelete(DatabaseConstant.UN_LOGISTIC_DELETED);
        Long keyId = cartDao.insert(cartEntity);
        return R.ok().put("keyId", keyId);
    }


    @GetMapping("/select")
    @DubboAndHTTPExceptionCatch
    public R select() {
        List<CartEntity> cartEntities = cartDao.selectByWrapper(new CartEntity());
        return R.ok().put("keyId", cartEntities);
    }
}
